﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'user_smslog';
</cfscript>

<!---手机发送短信验证码--->
<cffunction access="remote" name="sendVcode" returnFormat="json">
	<cfparam name="type" default="0" type="integer">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
  <cfif isdefined('mobile') and isnumeric(mobile)>
  	<cfif len(mobile) eq 11>
			<cfscript>
      //短信平台设置
      actionurl = 'http://121.101.221.34:8888/sms.aspx';
      userid = 1564;
      account = 'jkcs45';
      password = 'jkcs45888';
      vcode = RandRange(100000,999999);
			switch (type){
				case 0:
					content = '感谢您在中国老虎注册，验证码为' & vcode & '。客服热线：400-108-6488（工作日9-18点）';
					break;
				case 1:
					content = '您于' & dateformat(now(),'yyyy-mm-dd') & ' ' & TimeFormat(now(),'HH:mm:ss') & '申请重置密码，验证码为' & vcode & '。客服热线400-180-6488（工作日9-18点）';
					//content = '您申请重置CHINALAOHU.COM登录密码，验证码为' & vcode & '。客服热线021-32519063（工作日9-18点）';
					break;
			}
      </cfscript>
			<!---判断手机号是否注册--->
      <!---临时取消1--->
      <cfquery datasource="#DB#" name="checkmobile">
      select uid,uuid
      from user_base
      where mobile = '#mobile#'
      </cfquery>
      
      
      <cfif checkmobile.recordcount eq 0>
      	<cfswitch expression="#type#">
        	<cfcase value="0">
            <cftry>
            	<cfhttp url="#actionurl#?action=send&userid=#userid#&account=#account#&password=#password#&mobile=#mobile#&content=#content#" 
              	method="GET" 
                result="result" 
                charset="utf-8">
              </cfhttp>
              <cfscript>
              fc = result.Filecontent;
							if (isxml(fc)){
								fcxml = XmlParse(fc);
								returnstatus = XmlSearch(fcxml,'/returnsms/returnstatus')[1].XmlText;
								//writedump(returnstatus);
								if (returnstatus eq 'Success'){
									send = 1;
								}
								else {
									send = 0;
								}
							}
							else {
								send = 0;
							}
              </cfscript>
              <cfcatch type="any">
              	<cfset send = 0>
              </cfcatch>
            </cftry>
            <cfif isdefined('send') and send eq 1>
              <cfquery datasource="#DB#">
              replace into user_regvcode(mobile,vcode,cuts)
              value('#mobile#','#vcode#',UNIX_TIMESTAMP())
              </cfquery>
              <cfinvoke component="sms" method="smslog" mobile="#mobile#" sendobj="#type#" content="#content#" />
              <cfscript>
              //用户密码重置
              j = {"success":"1"};
              </cfscript>
            </cfif>
          </cfcase>
          <cfcase value="1">
						<cfscript>
						//没有注册过不能重置密码
            j = {"success":"0","errCode":"1"};
            </cfscript>
              
          </cfcase>          
          
        </cfswitch>
        
      <cfelse>
      	<cfswitch expression="#type#">
        	<cfcase value="0">
						<cfscript>
            j = {"success":"0","errCode":"1"};
            //j = {"success":"0","msg":"该手机号已经被注册"};
            </cfscript>
            
          </cfcase>
        	<cfcase value="1">
            <cftry>
            	<cfhttp url="#actionurl#?action=send&userid=#userid#&account=#account#&password=#password#&mobile=#mobile#&content=#content#" 
              	method="GET" 
                result="result" 
                charset="utf-8">
              </cfhttp>
              <cfscript>
              fc = result.Filecontent;
							if (isxml(fc)){
								fcxml = XmlParse(fc);
								returnstatus = XmlSearch(fcxml,'/returnsms/returnstatus')[1].XmlText;
								//writedump(returnstatus);
								if (returnstatus eq 'Success'){
									send = 1;
								}
								else {
									send = 0;
								}
							}
							else {
								send = 0;
							}
              </cfscript>
              <cfcatch type="any">
              	<cfset send = 0>
              </cfcatch>
            </cftry>
            <cfif isdefined('send') and send eq 1>
              <cfquery datasource="#DB#">
              replace into user_userpwdvcode(mobile,vcode,cuts)
              value('#mobile#','#vcode#',UNIX_TIMESTAMP())
              </cfquery>
              <cfinvoke component="sms" method="smslog" mobile="#mobile#" sendobj="#type#" content="#content#" />
              <cfscript>
              //用户密码重置
              j = {"success":"1"};
              </cfscript>
            </cfif>
            
          </cfcase>
          
        </cfswitch>
      </cfif>
      
    <cfelse>
			<cfscript>
			j = {"success":"0","errCode":"-1"};
      //j = {"success":"0","msg":"目前只支持国内的手机号码"};
      </cfscript>
    </cfif>
  <cfelse>
		<cfscript>
		//,"msg":"请正确填写手机号码"
    j = {"success":"0","errCode":"-1"};
    </cfscript>
  </cfif>


	
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>

</cffunction>

<!---短信发送日志--->
<cffunction access="public" name="smslog" returntype="any">
<cfquery datasource="#DB#">
insert into user_smslog(mobile,senddt,sendobj,content)
values('#mobile#',#now()#,#sendobj#,'#content#')
</cfquery>
</cffunction>

</cfcomponent>